package com.aier.admin.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.service.IAdminBuyService;
import com.aier.common.dao.ICommonDAO;
import com.aier.school.entity.School;
import com.aier.user.common.UserFinalPageSize;
import com.aier.user.entity.User;

@Scope("prototype")
@Component("adminBuyAction")
public class AdminBuyAction extends AdminBaseAction {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    @Resource(name = "adminBuyService")
    private IAdminBuyService adminBuyService;
    //页数
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    //错误码
    private int s;
    
    // 学校列表
    private List<School> schoolList;
    // 学校名称
    private String sname;
    // 学校所在省市编号
    private Integer cid;
    // 学校id
    private Long sid;
    // 购买方式（按月，按天）
    private Integer method;
    // 购买的月数或终止日期
    private String edate;
    // 用户帐号
    private String account;
    // 用户列表
    private List<User> userList;
    // 用户id
    private Long uid;
    
    private String sdate;//日期查询条件
    

	@Override
    public String execute(){
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String searchSchool() {
        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        
        map = adminBuyService.searchSchoolList(sname, cid, page, UserFinalPageSize.PROXY_SCHOOLS_PAGESIZE);
        schoolList = (List<School>)map.get(ICommonDAO.OBJ_LIST);
        
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 根据学校购买服务
     * @return
     */
    public String buyServiceBySchool() {
        s = adminBuyService.insertServiceBySchool(sid, method, edate);
        return SUCCESS;
    }
    
    /**
     * 查询用户列表
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchUserList() {
        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        
        map = adminBuyService.searchUserList(account,sdate,page, UserFinalPageSize.PROXY_SCHOOLS_PAGESIZE);
        userList = (List<User>)map.get(ICommonDAO.OBJ_LIST);
        
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 根据用户购买服务
     * @return
     */
    public String buyServiceByUser() {
        s = adminBuyService.insertServiceByUser(uid, method, edate);
        return SUCCESS;
    }
    
    /**
     * 取消用户服务
     * @return
     */
    public String cancelServiceByUser() {
        s = adminBuyService.deleteServiceByUser(uid);
        return SUCCESS;
    }
    
    /**
     * 转移服务
     * @return
     */
    public String transferServiceByUser() {
        s = adminBuyService.insertNewService(uid,account);
        return SUCCESS;
    }

    public int getPage() {
        return page;
    }


    public void setPage(int page) {
        this.page = page;
    }


    public int getPage_size() {
        return page_size;
    }


    public int getPage_count() {
        return page_count;
    }


    public int getCount() {
        return count;
    }


    public int getS() {
        return s;
    }

    public List<School> getSchoolList() {
        return schoolList;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public void setCid(Integer cid) {
        this.cid = cid;
    }

    public void setSid(Long sid) {
        this.sid = sid;
    }

    public void setAdminBuyService(IAdminBuyService adminBuyService) {
        this.adminBuyService = adminBuyService;
    }

    public void setMethod(Integer method) {
        this.method = method;
    }

    public void setEdate(String edate) {
        this.edate = edate;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public List<User> getUserList() {
        return userList;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }
    
    public void setSdate(String sdate) {
		this.sdate = sdate;
	}

}
